<?php
declare (strict_types = 1);

namespace app\admin\middleware;

use think\facade\Session;

class Auth
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        switch ($request->pathinfo()) {
            // 判断当前是否登录了
            case 'auth/login/checkSs':
                if ( ! Session::get('admin_id')) {
                    return getErrorJson();
                }else {
                    return getJson();
                }
                break;
            // 登录不需要验证什么
            case 'auth/login/login':
                break;
            default:
                if ( ! Session::get('admin_id')) {
                    return getErrorJson('请先登录');
                }
                break;
        }

        return $next($request);
    }
}
